package app.web.admin.domain.ao;

import app.config.Config;
import com.gitee.feizns.dynamic.bean.Convertible;
import com.gitee.feizns.quickstart.validation.Verifiable;
import com.gitee.feizns.quickstart.validation.constraints.DynamicValidate;
import com.gitee.feizns.quickstart.web.ex.BadRequestException;
import lombok.Data;

import javax.validation.constraints.NotBlank;

/**
 * 角色创建参数
 * @author feizns
 * @since 2025-04-09
 */
@Data
@DynamicValidate
public class RoleCreateAo implements Convertible, Verifiable {

    /**
     * 角色名称
     */
    @NotBlank(message = "角色名称不能为空.")
    private String name;

    /**
     * 角色组名称
     */
    @NotBlank(message = "角色组名称不能为空.")
    private String group;

    @Override
    public boolean validate() {
        if ( !Config.roleGroupNames().contains(group) )
            throw new BadRequestException(String.format("角色组不存在: '%s'", group));
        return Verifiable.super.validate();
    }

}
